package com.hzdl.house_mgr.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ChkUserIsLogin implements Filter {

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;

        String uri = request.getRequestURI();
       /* System.out.println(uri);*/

        if(uri.startsWith("/car/static") || uri.equals("/car/loginInit") || uri.equals("/car/login") || uri.equals("/car/autoYzm") || uri.equals("/car/chkYzm")){
            filterChain.doFilter(servletRequest,servletResponse);
        }else{
            //获取sessiohn对象
            Object session_user = request.getSession().getAttribute("session_user");
            if(session_user != null ){
                filterChain.doFilter(servletRequest,servletResponse);
            }else{
                ((HttpServletResponse)servletResponse).sendRedirect("/car/loginInit");
            }
        }


    }
}
